<extend name="Layout:ly2"/>
<block name="head">
<script>
    $(function(){
        $("#btn-submit").click(function(){
            var id = $("input[name='id']").val();
            var uid = $("input[name='uid']").val();
            var content = $("textarea").val();
            var addtime = $("input[name='addtime']").val();
            var catid = $("input[name='catid']").val();
            if (content == '') {layer.msg('内容不能为空');return false;}
            if (addtime == '') {layer.msg('时间不能为空');return false;}
            if (catid == '') {layer.msg('问题分类不能为空');return false;}

            $.get("{:U('Admin/Ask/question_edit')}",{'action':'edit','id':id,'uid':uid,'content':content,'addtime':addtime,'catid':catid},function(msg){
                if(msg == 1){
                    layer.msg("更新成功，1秒后自动关闭~~",{ico:1,time:1000},function(){
                        parent.window.location.reload();    //刷新父页面
                    })
                }else if(msg == 2){
                    layer.msg("参数异常，1秒后自动关闭~~",{ico:1,time:1000},function(){
                        parent.window.location.reload();    //刷新父页面
                    })
                }else{
                    layer.msg("更新失败，1秒后自动关闭~~",{ico:1,time:1000},function(){
                        parent.window.location.reload();    //刷新父页面
                    })
                }
            })
        })
        
        $("#select_first").change(function () {
            var catid = this.options[this.selectedIndex].value;
            $.get("{:U('Admin/Ask/getCategory')}",{'action':'cat','cat_id':catid},function(msg){
                //判断数组是否大余0 显示下拉
                if(msg.length > 0){
                    var str;
                    $.each(msg,function(index,value){
                        str += "<option value='"+value['id']+"'>"+value['cat_name']+"</option>";
                    })

                    $("#select_second option").remove();
                    $("#select_second").append("<option value='-1'>请选择二级分类</option>");
                    $("#select_second").show().append(str);
                }else{
                    $("#select_second").hide();
                    $("#select_three").hide();
                }
            })
            $("#catid").val(catid);
        })

        $("#select_second").change(function () {
            var catid = this.options[this.selectedIndex].value;
            $.get("{:U('Admin/Ask/getCategory')}",{'action':'cat','cat_id':catid},function(msg){

                //判断数组是否大余0 显示下拉
                if(msg.length > 0){
                    var str;
                    $.each(msg,function(index,value){
                        str += "<option value='"+value['id']+"'>"+value['cat_name']+"</option>";
                    })
                    $("#select_three option").remove();
                    $("#select_three").append("<option value='-1'>请选择三级分类</option>");
                    $("#select_three").show().append(str);
                }else{
                    $("#select_three").hide();
                }
            })
            $("#catid").val(catid);
        })

        $("#select_three").change(function () {
            var catid = this.options[this.selectedIndex].value;
            $("#catid").val(catid);
        })
    })
</script>
</block>
<block name="body">
    <div class="container-fluid">
        <h3 id="title" align="center">修改问题</h3>
        <div class="padding20">
            <div class="form-horizontal p90">
                <div class="form-group">
                    <label class="col-sm-2 control-label">问题id：</label>
                    <div class="col-sm-8">
                        <input type="text" name="id" class="form-control" id="id" required value="{$edit_list['0']['id']}" readonly />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">用户名：</label>
                    <div class="col-sm-8">
                        <input type="text" name="nickname" class="form-control" id="nickname" value="{$edit_list[0]['nickname']}" readonly/>
                    </div>
                    <div class="col-sm-2"></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">用户id：</label>
                    <div class="col-sm-8">
                        <input type="text" name="uid" class="form-control" id="uid" value="{$edit_list[0]['uid']}" />
                    </div>
                    <label class="col-sm-2 control-label">请修改用户id</label>
                    <div class="col-sm-2"></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">问题内容：</label>
                    <div class="col-sm-8">
                        <textarea type="text" name="content" class="form-control" id="content" >{$edit_list[0]['content']}</textarea>
                    </div>
                    <div class="col-sm-2"></div>
                </div>
                <div class="form-group" style="display: none;">
                    <label class="col-sm-2 control-label">发问时间：</label>
                    <div class="col-sm-8">
                        <input type="text" name="addtime" class="form-control" id="addtime" value="{$edit_list[0]['addtime']}" />
                    </div>
                    <div class="col-sm-2"></div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">问题分类：</label>
                    <div class="col-sm-8">
                        <!--<input type="text" name="catname" class="form-control" id="catname" value="{$edit_list[0]['cat_name']}" readonly/>-->

                        <select class="form-control" id="select_first" style="width: 30%;float: left;margin-right: 15px;">
                            <option value="-1">请选择分类</option>
                            <foreach name="p_data" item="vo" key="k" >
                            <option value="{$vo.id}">{$vo.cat_name}</option>
                            </foreach>
                        </select>

                        <select class="form-control" id="select_second" style="display:none;width: 30%;float: left;margin-right: 15px;">
                        </select>

                        <select class="form-control" id="select_three" style="display:none;width: 30%;float: left;margin-right: 15px;">
                            <option value="-1">请选择三级分类</option>
                        </select>

                    </div>
                    <div class="col-sm-2"></div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">问题分类id</label>
                    <div class="col-sm-8">
                        <input type="text" name="catid" class="form-control" id="catid" value="{$edit_list[0]['catid']}" />
                    </div>
                    <label class="col-sm-2 control-label">请修改分类id</label>
                    <div class="col-sm-2"></div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" id="btn-submit" class="btn btn-success">修改</button>&nbsp;&nbsp;&nbsp;&nbsp;
                        <button type="reset" class="btn btn-default">重置</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

</block>